﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Android_Helper.golang
{
    class GolangTypeUtils
    {
        public static string DbTypeToGolang(string typeName) {
            string value = typeName.Trim().ToLower();
            string ret = string.Empty;
            switch (value)
            {
                case "double": ret = "float64"; break;
                case "bigint": ret = "int64"; break;
                case "datetime": ret = "string"; break;
                case "varchar": ret = "string"; break;
                case "nvarchar": ret = "string"; break;
                case "tinyint": ret = "bool"; break;
                case "int": ret = "int32"; break;
                default: Console.WriteLine("类型未处理。"+value); ret = "string"; break;
            }
            return ret;
        }

        public static string DbTypeToGolangNull(string typeName)
        {
            string value = typeName.Trim().ToLower();
            string ret = string.Empty;
            switch (value)
            {
                case "double": ret = "sql.NullFloat64"; break;
                case "bigint": ret = "sql.NullInt64"; break;
                case "datetime": ret = "sql.NullString"; break;
                case "varchar": ret = "sql.NullString"; break;
                case "nvarchar": ret = "sql.NullString"; break;
                case "tinyint": ret = "sql.NullBool"; break;
                case "int": ret = "sql.NullInt32"; break;
                default: Console.WriteLine("类型未处理。" + value); ret = "sql.NullString"; break;
            }
            return ret;
        }

        public static string DbTypeNullToGo(string typeName)
        {
            string ret = typeName.Replace("sql.Null", "");
            return ret;
        }
    }
}
